<?php session_start();//启用回话窗   ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>管理员界面</title>

<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/landing-page.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- text fonts -->
<link rel="stylesheet" href="fonts/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="css/ace.min.css" />

<!--[if lte IE 9]>
<link rel="stylesheet" href="css/ace-part2.min.css" />
<![endif]-->
<link rel="stylesheet" href="css/ace-rtl.min.css" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="css/ace-ie.min.css" />
<![endif]-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap.js"></script>
    

    
    
</head>
<body>
<style>
#myButton{
	border:1px solid #FFF;
	font-family: '微软雅黑';
}
</style>
<div id="txtHint">
<div class="intro-header">
    <!--头部查询控件-->
    <div class="container" style="padding:20px;">
        <nav class="navbar navbar-default" role="navigation">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">InQuiry</a>
            </div>
            <div id="myexample">
               <ul class="nav navbar-nav" >
                  
                   <li class="dropdown">
                     
                       <a href="#"   class="dropdown-toggle" data-toggle="dropdown"  onclick="dropDown()">查询条件<span class="caret"></span></a>
                       <ul class="dropdown-menu">
                           <li><a href="#" id="one" rel="userName" onclick="onSelect_1()">按用户名进行查询</a></li>
                           <li><a href="#" id="two" rel="telNumber" onclick="onSelect_2()">按手机号进行查询</a></li>
                           <li class="divider"></li>
                           <li><a href="#" id="three" rel="reg_date" onclick="onSelect_3()">按登陆时间进行查询</a></li>
                       </ul>
                   </li>
                   
                   <li><input type="text" class="form-control input-sm" id="condition"  name="condition" placeholder="请输入条件下的查询字符" style=" min-height:45px; min-width:300px" /></li>  
                   <li><a href="#" onclick="condition()">查询</a></li>

               </ul>
            </div>
        </nav>
    </div>
    

    <!--主体表格-->
    <table  class="table  table-bordered  table-condensed"  id="userInformation" >
        <!--用户信息表头-->
        <caption style="text-align: center;font-size: 200%;font-family:'微软雅黑';color:#ffffff;"><b>The User Information<hr class="intro-divider"></b></caption>
        
        <thead>
        <tr>
            <th>用户名</th>
            <th>邮箱</th>
            <th>电话号码</th>
            <th>登陆时间</th>
            <th>权限</th>
        </tr>
        </thead>
        <!--构建表身部分-->
        <tbody>
        <!--从数据库中返回整个用户信息表单-->
        
        <div id='txtHint'>
        <?php
        // 创建连接
        $conn = new mysqli("localhost", "root","wei1995629", "information");
        // 检测连接
        if ($conn->connect_error) {
            die("连接失败: " . $conn->connect_error);
        }
        
        $result = mysqli_query($conn,"SELECT * FROM userInformation");
        
        if ($result->num_rows > 0) {
            // 输出每行数据
            while($row = $result->fetch_assoc()) {
                echo 
                "<tr> "
                ."<td>" .$row["userName"] ."</td>"
                ."<td>" .$row["email"] ."</td>"
                ."<td>" .$row["telNumber"] ."</td>"
                ."<td>" .$row["reg_date"] ."</td>";
                if("ADMIN" == $row["admin"]){
                    echo "<td>" ."<button class='btn btn-info'  type='button' id='myButton'>已拥有权限</button>" ."</td>";
                }
                else{
                    echo "<td>" ."<button class='btn btn-info'  type='button' id='myButton' value='" .$row['userName'] ."' onclick='rootSeting(this.value)' >设置为管理</button>" ."</td>";
                }
    
                echo"</tr>";
                }
        } 
        else {
            echo "No More.";
        }
        echo "";
        
        $conn->close();//关闭数据库
        ?>
 
         
        </tbody>
    </table>

</div>
</div> 

<script  type="text/javascript">

    /* 修改用户权限 */
    function rootSeting(str){
    	var xmlhttp;
    	xmlhttp=new XMLHttpRequest(); 
    	var url="http://localhost/Zend/01.00/01.01/rootSet.php";
    	url=url+"?q="+str;
    	//url=url+"&sid="+Math.random();
    	
    	xmlhttp.onreadystatechange=stateChanged;
    	
    	xmlhttp.open("GET",url,true);
    	//xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    	xmlhttp.send();
    	function stateChanged() 
    	{ 
    	if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
    	 { 
    		window.location.reload(); 
    	 //document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
    		alert("修改成功！！"); 	 
    	 } 
    	}
    	return xmlhttp;
		/* //创建 XMLHttpRequest 对象
    	function GetXmlHttpObject()
    	{
    	var xmlHttp=null;
    	try
    	 {
    	 // Firefox, Opera 8.0+, Safari
    	 xmlHttp=new XMLHttpRequest();
    	 }
    	catch (e)
    	 {
    	 //Internet Explorer
    	 try
    	  {
    	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	  }
    	 catch (e)
    	  {
    	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  }
    	 }			 */
    } 
	//下拉菜单
    function dropDown(){
    		$('.dropdown-toggle').dropdown("");
   	 		$('.dropdown-toggle').dropdown("toggle");
        } 

	//前提条件确定
	function onSelect_1(){document.getElementById('one').id = "five";}
	function onSelect_2(){document.getElementById('two').id = "five";}
	function onSelect_3(){document.getElementById('three').id = "five";}
    //条件查询
    function condition(){
    	//alert("hahaha");
    	var answer = document.getElementById('condition').value;//获取当前查询值
    	var an = document.getElementById('five').rel;
    	 
    	var xmlhttp;
    	xmlhttp=new XMLHttpRequest(); 
    	var url="http://localhost/Zend/01.00/01.01/conditionMatch.php";
/*      	url=url+"?q="+an;
    	url=url+"p="+answer; */ 
    	alert(url);
    	//url=url+"&sid="+Math.random();
    	xmlhttp.onreadystatechange=stateChanged;
    	
    	xmlhttp.open("POST",url,true);
    	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    	xmlhttp.send("q="+an+"&p="+answer);
    	function stateChanged() 
    	{ 
    	if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
    	 { 
    	 	document.getElementById("txtHint").innerHTML=xmlhttp.responseText; 
    		alert("查询成功！！"); 	 
    	 } 
    	}
    	//return xmlhttp;
        }  
       
</script>    

</body>
</html>
